﻿using GCC.Container.Abstracts;
using GCC.Container.LogProviders;

using APMClient = System.APMServer.Client.Manager;
using CacheManager = GCC.Container.Cache.Manager;

namespace GCC.APIContainer
{
    /// <summary>
    /// 容器上下文
    /// </summary>
    public partial class GCCContext : AbsGCCContext, IDisposable
    {


        /// <summary>
        /// 日志
        /// </summary>
        private readonly AbsGCCLogger? _logger = GCCLoggerProvider.Instance?.CreateLogger<GCCContext>();
        /// <summary>
        /// apm客户端
        /// </summary>
        private readonly APMClient? _apmClient = null;


        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="cacheManager">缓存管理器</param>
        /// <param name="pointName">当前节点</param>
        /// <param name="_client">APM收集客户端</param> 
        public GCCContext(CacheManager cacheManager, string pointName, APMClient? _client)
        {
            this._cache = cacheManager;
            this._pointName = pointName;
            this._apmClient = _client;
        }

        /// <summary>
        /// 销毁事件
        /// </summary>
        /// <param name="flage"></param>
        public override void Dispose(bool flage)
        {
            base.Dispose(flage);

        }



        /// <summary>
        /// 发送一个跟踪信息
        /// </summary>
        /// <param name="type">类型</param> 
        /// <param name="resourceName">资源秒数</param> 
        /// <param name="value">信息</param>
        /// <param name="path">路径</param>
        /// <param name="from">从哪里来</param>
        /// <param name="method">函数</param> 
        public override void SaveTrace(string type,
            string resourceName = "",
            string path = "",
            string method = "",
            string from = "",
            string value = "")
        {
            _apmClient?.SendTraceItem(
                type: type,
                sessionID: EventID ?? "",
                resourceName: resourceName,
                pointName: _pointName,
                value: value,
                path: path,
                from: from,
                method: method,
                currentEventID: EventID ?? "");
        }
    }
}
